<template>
  <div>
    <!-- 搜索条件盒子 -->
    <div>
      <p class="pinformation">搜索条件</p>
      <el-form label-width="70" ref="queryRef" :model="queryParams">
        <el-row>
          <el-col :span="20">
            <el-form-item label="领用人：" prop="projectCode">
              <el-input
                maxlength="100"
                clearable
                placeholder="请输入领用人"
                v-model="queryParams.projectCode"
                @keyup.enter="handleQuery"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="10">
            <el-form-item label="所属组：" prop="projectName">
              <el-input
                maxlength="100"
                clearable
                placeholder="请输入所属组"
                v-model="queryParams.projectName"
                @keyup.enter="handleQuery"
              />
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item
              label="当前状态："
              prop="projectName"
              label-width="80"
            >
              <el-input
                maxlength="100"
                clearable
                placeholder="请输入当前状态"
                v-model="queryParams.projectName"
                @keyup.enter="handleQuery"
              />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-row justify="center">
              <el-button type="success" @click="handleQuery">搜索</el-button>
            </el-row>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="20">
            <el-form-item label="领取时间：">
              <el-date-picker
                v-model="dateRange"
                value-format="YYYY-MM-DD"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-row justify="center">
              <el-button class="business resetBtn" @click="resetQuery"
                >重置</el-button
              >
            </el-row>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- 检测类别列表盒子 -->
    <div>
      <el-row style="justify-content: space-between">
        <el-row>
          <p class="pinformation">领取表列表</p>
          <p class="totalStyle">共 {{ total }} 条数据</p>
        </el-row>
        <el-row style="padding-bottom: 5px">
          <el-button type="success" icon="plus" @click="createTable" link>新增</el-button>
        </el-row>
      </el-row>
      <el-table
        ref="mainTableRef"
        :data="receiveList"
        :row-class-name="tableRowClass"
        @row-click="rowClick"
        v-loading="loading"
      >
        <el-table-column label="领用时间" align="center" prop="" />
        <el-table-column label="领取人" align="center" prop="nickName" />
        <el-table-column label="所属组" align="center" prop="userGroupName" />
        <el-table-column label="当前状态" align="center" prop="" />
        <el-table-column label="操作" align="center" width="100">
          <template #default="scope">
            <el-button link icon="EditPen">签字</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
  </div>
</template>

<script setup>
import { getTaskList } from "@/api/sampleManage/sampleGet";

const { proxy } = getCurrentInstance();
const {  sys_degree } = proxy.useDict(
  "sys_degree"
);
const {
  sys_contract_type,
} = proxy.useOrgDict(
  "sys_contract_type",
);
const total = ref(0);
const receiveList = ref([]);
const dateRange = ref([]);
const loading = ref(true);

const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    userStatus: props.userStatus,
  },
});

const { queryParams } = toRefs(data);

//定义参数 已经选中的ITEMID
const props = defineProps({
    userStatus: {
    type: Number, //参数类型
  },
});

watch(
  () => total.value,
  () => {
    if (total.value) {
      heightParams.value = [{ tableName: "main", bottomHeight: 74 }];
    } else {
      heightParams.value = [{ tableName: "main", bottomHeight: 21 }];
    }
    getTableHeight();
  }
);

const heightParams = ref([{ tableName: "main", bottomHeight: 21 }]);
function getTableHeight() {
  proxy.adaptiveHeight(proxy, heightParams.value);
}
onMounted(() => {
  nextTick(() => {
    getTableHeight();
    window.addEventListener("resize", getTableHeight);
  })
})
onUpdated(() => {
  nextTick(function () {
    getTableHeight();
  });
});

onBeforeUnmount(() => {
  window.removeEventListener("resize", getTableHeight);
});

const emits = defineEmits(["getSeqId","getTableId"]);

function getList() {
  loading.value = true;
  getTaskList(proxy.addDateRange(queryParams.value, dateRange.value)).then(
    (res) => {
      receiveList.value = res.rows;
      total.value = res.total;
      loading.value = false;
    }
  );
}

function rowClick(row) {
  emits("getSeqId", row.myId);
  heightBright.value = row.myId;
}

function handleQuery() {
  queryParams.pageNum = 1;
  getList();
}
function resetQuery() {
  proxy.resetForm("queryRef");
  dateRange.value = [];
  getList();
}

function createTable(){
  emits("getTableId", "1684791502188847106");
  heightBright.value = ""
}

const heightBright = ref("");
function tableRowClass({ row }) {
  if (row) {
    if (row.myId == heightBright.value) {
      return "current-row";
    }
    return "";
  }
}

defineExpose({
  heightBright,
  getList
});

getList();
</script>
